package com.atguigu.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

@WebServlet(urlPatterns = "/Servlet08KillSession")
public class Servlet08KillSession extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();

        // 调用方法，让 session 对象立即失效
        session.invalidate();

        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().write("<h1>session 对象失效了</h1>");
    }
}
